package com.zues.samples.web;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zues.samples.model.PagerModel;
import com.zues.samples.service.ScoreService;
import com.zues.samples.service.modelVO.ScoreVO;

@Controller
public class ScoreController {

	@Autowired
	private ScoreService scoreService;
	
	@RequestMapping(value = "/listscore", method = RequestMethod.GET)
	public String users(Model model) throws Exception {
		PagerModel<ScoreVO> list = scoreService.findAllByPage();
		model.addAttribute("scorelist", list);
		return "teacher/scores";
	}
	
	@RequestMapping(value = "/showscore", method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> showScore (Integer scoreId) {
		Map<String,Object> modelMap = new HashMap<String,Object>();
		try {
			ScoreVO scoreVO = new ScoreVO();
			scoreVO = scoreService.showScore(scoreId);
			modelMap.put("score", scoreVO);
			modelMap.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			modelMap.put("success", false);
		} 
		return modelMap;
	}
}
